package com.example.pay.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.pay.dto.PrepayRequest;
import com.example.pay.dto.PrepayResponse;
import com.example.pay.entity.MemberOrder;
import com.example.pay.entity.PaymentTransaction;
import com.example.pay.mapper.MemberOrderMapper;
import com.example.pay.mapper.PaymentTransactionMapper;
import com.example.pay.service.PayService;
import com.example.pay.service.NotifyService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/pay")
@RequiredArgsConstructor
public class PayController {
    private final PayService payService;
    private final PaymentTransactionMapper transactionMapper;
    private final MemberOrderMapper orderMapper;
    private final NotifyService notifyService;

    @PostMapping(value = "/prepay", consumes = MediaType.APPLICATION_JSON_VALUE)
    public PrepayResponse prepay(@RequestBody PrepayRequest request) {
        return payService.prepay(request);
    }

    // 微信回调（v3：包含AES-GCM解密）
    @PostMapping(value = "/notify/wechat")
    public Map<String, Object> wechatNotify(@RequestBody String body) {
        return notifyService.handleWeChatNotify(body);
    }

    // 支付宝回调（RSA2验签）
    @PostMapping(value = "/notify/alipay")
    public String alipayNotify(@RequestParam Map<String, String> params) {
        return notifyService.handleAlipayNotify(params);
    }
}